package com.example.shop_2208.mvvmdemo

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Button
import android.widget.EditText
import com.blankj.utilcode.util.ToastUtils
import com.example.shop_2208.R

class MainActivity : AppCompatActivity() {
    val vm = LoginViewModel()
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main2)
        val etName = findViewById<EditText>(R.id.et_name)
        val etPwd = findViewById<EditText>(R.id.et_pwd)
        val login = findViewById<Button>(R.id.login)

        login.setOnClickListener {
            vm.login(etName.text.toString(),etPwd.text.toString())
        }
        vm.loginSuccess.observe(this){
            ToastUtils.showLong(it.message)
        }
        vm.loginFail.observe(this){
            ToastUtils.showLong(it)
        }
    }
}